package cn.b.sky.flowable.service.impl;

import cn.b.sky.flowable.dao.ProcessModelCategoryDao;
import cn.b.sky.flowable.model.ProcessModelCategory;
import cn.b.sky.flowable.service.ProcessModelCategoryService;
import cn.b.sky.common.exception.ImeException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("processModelCategoryService")
public class ProcessModelCategoryServiceImpl implements ProcessModelCategoryService {


  @Autowired
  private ProcessModelCategoryDao processModelCategoryDao;

  @Override
  public List<ProcessModelCategory> getProcessModelCategoryTree(String tenantId) {
    return this.processModelCategoryDao.selectAllProcessModelCategory(tenantId);
  }

  @Override
  public void saveProcessModelCategory(ProcessModelCategory category) {
    if (category != null) {
      this.processModelCategoryDao.saveProcessModelCategory(category);
    }
  }

  @Override
  public ProcessModelCategory getProcessModelCategoryByCategory(String category, String tenantId) {
    if (!StringUtils.isBlank(category)) {
      return this.processModelCategoryDao.getProcessModelCategoryByCategory(category, tenantId);
    }
    throw ImeException.newException("ModelCategory_NUll.M", new String[0]);
  }

  @Override
  public Integer checkeCategoryIsExits(String category, String tenantId) {
    if (StringUtils.isBlank(category)) {
      return Integer.valueOf(0);
    }
    return this.processModelCategoryDao.checkeCategoryIsExits(category, tenantId);
  }

  @Override
  public void modifyModelCategory(ProcessModelCategory category) {
    if ((category != null) && (!StringUtils.isBlank(category.getCategory()))) {
      this.processModelCategoryDao.updateProcessModelCategory(category);
    }
  }

  @Override
  public void saveModelCategory(ProcessModelCategory category) {
    if ((category != null) && (!StringUtils.isBlank(category.getCategory()))) {
      this.processModelCategoryDao.saveProcessModelCategory(category);
    }
  }

}
